package com.controller.ssjf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.common.utils.base.Const;
import com.controller.base.BaseController;
import com.entity.Complaint;
import com.entity.User;
import com.service.ComplaintService;
import com.service.UserService;

@Controller
@RequestMapping("/ssjf")
public class SSJFComplaintController extends BaseController<Object>{

	@Autowired
	private ComplaintService complaintService;
	@Autowired
	private UserService userService;
	
	@RequestMapping("page/comment.html")
	public String comment(Model model, User complained)throws Exception{
		complained.setDetail(true);
		complained = userService.find(complained).get(0);
		model.addAttribute("complained", complained);
		return "ssjf/pages/comment";
	}
	
	
	@RequestMapping("/commentlist.dat")
	@ResponseBody
	public AjaxRes list(User user, Page<User> page){
		AjaxRes res = new AjaxRes();
		user.setFileRemark("portrait");
		Page<User> users = userService.findDetailByPage(user, page);
		res.setSucceed(users, Const.DATA_SUCCEED);
		return res;
	}
	
	@RequestMapping("/comment.dat")
	@ResponseBody
	public AjaxRes comment(Complaint complaint){
		AjaxRes res = new AjaxRes();
		User user = (User) getRequest().getSession().getAttribute("loggedUser");
		if(user == null){
			res.setFailMsg(Const.DATA_FAIL);
			return res;
		}
		complaint.setComplainantId(user.getId());
		complaintService.insert(complaint);
		res.setSucceedMsg(Const.DATA_SUCCEED);
		return res;
	}
	
}
